/**
 * Copyright (C), 2018-2020, 飞尔智能有限公司
 * FileName: FeignConfig
 * Author:   杨乐
 */
package com.yangle.feign;

import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.Map;

/**
 * @description:
 * @Author 杨乐
 * @Date 2020/2/4 9:28
 * @Version 1.0
 **/
@Configuration
public class FeignConfig {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }
    @Bean
    public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor(){
        return new FeignBasicAuthRequestInterceptor();
    }
    class FeignBasicAuthRequestInterceptor implements RequestInterceptor{

        @Override
        public void apply(RequestTemplate requestTemplate) {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            String token = request.getHeader("token");
            requestTemplate.header("token",token);
            Map<String, Collection<String>> headers= requestTemplate.headers();
        }
    }
    @Bean
    public UserFeignFallBack userFeignFallBack(){
        return new UserFeignFallBack();
    }
}
    
